package com.atguigu.tingshu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

@Component
public class ThreadPoolExecutorConfig {
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        int cpuCoreNum = Runtime.getRuntime().availableProcessors()*2;
        System.out.println("核心线程数："+cpuCoreNum);
        return new ThreadPoolExecutor(
                cpuCoreNum,
                cpuCoreNum*2,
                60L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
